package com.zhangmin.demo.controller;

import com.alibaba.fastjson.JSONObject;
import com.zhangmin.demo.annoation.RequestLimit;
import com.zhangmin.demo.vo.Params;
import org.springframework.web.bind.annotation.*;

/**
 * Created by zhangmin on 18/4/21.
 */
@RestController
@RequestMapping("/demo")
public class DemoController {

    @RequestLimit(count = 10, time = 5000)
    @RequestMapping("/hi")
    public String hi(@RequestParam String a) {
        return "params:" + JSONObject.toJSONString(a);
    }

    @RequestLimit(count = 10, time = 5000)
    @RequestMapping("/testException")
    public String testException() {
        throw new RuntimeException("101, Sam 错误");
    }

    @RequestMapping(value = "/hi2", method = RequestMethod.POST)
    public String hi2(@RequestBody Params params) {
        System.out.println(JSONObject.toJSONString(params));
        return "hi2";
    }

    @RequestMapping(value = "/testBeforeService", method = RequestMethod.POST)
    @ResponseBody
    public String testBeforeService(@RequestBody Params params) {
        return "params:" + JSONObject.toJSONString(params);
    }
}
